import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'objectToArray'
})
export class ObjectToArrayPipe implements PipeTransform {

  transform(value: { [key: string]: any }, sortRule?: 'up'|'down', property?: string): any[] {
    let result = Object.keys(value).map(key => value[key]);
    if(sortRule) {
      result.sort((a, b) => {
        if(property) {
          return a[property] - b[property];
        } else {
          return a - b;
        }
      });
      if(sortRule === 'down') {
        result.reverse();
      }
    }
    return result;
  }

}
